/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Control;

import DAO.SoundTrackJpaController;
import DAO.exceptions.NonexistentEntityException;
import DAO.exceptions.PreexistingEntityException;
import Entidad.SoundTrack;
import grlu.Main;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author USUARIO
 */
public class SoundTrackControl {
    private SoundTrackJpaController JPASound;
    
    public SoundTrackControl(){
        JPASound = new SoundTrackJpaController(Main.emf);
    }
        
    
    public SoundTrack findSoundTrack(String name){
        return JPASound.findSoundTrack(name);
    }    
    
    
    public int deleteSoundTrack(SoundTrack sound){
        try {
            JPASound.destroy(sound.getPicture());
        } catch (NonexistentEntityException ex) {
            return 1;
        }
        return 0;
    }
    
    public int createSoundTrack(SoundTrack sound){
        try {
            JPASound.create(sound);
        } catch (PreexistingEntityException ex) {
            return 2;
        } catch (Exception ex) {
            return 1;
        }
        return 0;
    }
}
